<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="java.util.Date" %>
<%@ page import="ut.data.User" %>
<%@ page import="ut.data.Profile" %>
<%@ page import="ut.data.Task" %>
<%@ page import="ut.res.Language" %>
<%@ page import="ut.util.DateTime" %>
<%
	User user = (User)session.getAttribute("user");
	int p = 1;
	long tid = 0;
	if(request.getParameter("tid") == null){
		response.sendRedirect("/task/task-list.jsp");
		return;
	}	
	try{
		tid = Long.parseLong(request.getParameter("tid"));
		if(request.getParameter("p") != null){
			p = Integer.parseInt(request.getParameter("p"));
		}
	}catch(NumberFormatException e){
		response.sendRedirect("/task/task-list.jsp");
		return;
	}
	
	Task task = Task.getSimpleTask(tid);
	if(task == null){
		response.sendRedirect("/task/task-list.jsp");
		return;
	}
	int maxPage = task.getMaxApplicationPage(tid, 10);
		if(p > maxPage){
			p = maxPage;
	}
	
	String lang =
		Language.getLanguage(task.fromLan).title + " <img src='/image/arrow.png' /> " + Language.getLanguage(task.toLan).title;
%>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>UT終極一翻！ | 付費案件公開資訊#<%= tid %></title>
	<link rel="stylesheet" type="text/css" href="/style.css" media="all" />
	<link rel="stylesheet" type="text/css" href="/css/task-detail.css" media="all" />
	<script type="text/javascript" src="/js/Utility.js"></script>
	<script type="text/javascript" src="/js/Message.js"></script>
	<script type="text/javascript" src="/js/Ajax.js"></script>
	<script type="text/javascript" src="/js/Button.js"></script>
	<script type="text/javascript" src="/js/Account.js"></script>
	<script type="text/javascript" src="/js/Task.js"></script>
	<script type="text/javascript" src="/script.js"></script>
</head>
<body onload="init();">
<%@ include file="/include/banner.jsp" %>
	<div class="content">
		<div class="title">付費案件公開資訊#<%= tid %></div>
		<div class="task block">
			<span class="tag top blue"><%= lang %></span>
			<div class="task-content">
				<div class="task-element">
					<div class="task-element-left">案主：</div>
					<div class="task-element-right">
						<a href="/account/member-info.jsp?uid=<%= task.employer %>&view=1"><%= User.getUserName(task.employer) %></a>
					</div>
				</div>
			
				<div class="task-element">
					<div class="task-element-left">案件價格：</div>
					<div class="task-element-right">NTD <%= task.price%> 元</div>
				</div>

				<div class="task-element">
					<div class="task-element-left">字數統計：</div>
					<div class="task-element-right">字數：<%= task.wordNumber %>，字元數：<%= task.characterNumber %>（包含空白字元）</div>
				</div>
				
				<div class="task-element">
					<div class="task-element-left">發案日期：</div>
					<div class="task-element-right"><%= DateTime.toDateTime(task.publishTime)%></div>
				</div>
				
				<div class="task-element">
					<div class="task-element-left">截止日期：</div>
					<div class="task-element-right"><%= DateTime.toDateTime(task.deadTime)%></div>
				</div>
				
				<div class="task-element">
					<div class="task-element-left">案件狀態：</div>
<%	
	if(task.state == Task.MATCHING){
%>
					<div class="task-element-right mark-green">媒合中</div>
<%
	}else if(task.state == Task.MATCHED || task.state == Task.TRANSLATED){
%>
					<div class="task-element-right mark-blue">進行中</div>
<%
	}else{
%>
					<div class="task-element-right mark-red">已結案</div>
<%
	}
%>
				</div>
				
				<div class="task-element">
					<div class="task-element-left">案件領域：</div>
					<div class="task-element-right"><%= task.domain%></div>
				</div>
				
				<div class="task-element">
					<div class="task-element-left">案件說明：</div>
					<div class="task-element-right"><%= task.description %></div>
				</div>
			</div>
			<div style="clear:both"></div>
			<div class="task-bottom">
<%
	if(user != null && user.id == task.employer){	//發案者管理連結
%>
				<span class="tag bottom tool blue"><a href="/task/task-detail.jsp?tid=<%= tid %>" class="tool">案件管理</a></span>
<%
	}
	//接案申請
	if((user == null || user.id != task.employer) && task.state == Task.MATCHING){
		if(user == null){	//未登入
%>
				<span class="tag bottom tool blue" onclick="Task.applyTask(-1);">提出接案申請</span>
<%
		}else if(user.verify == 0){	//未驗證E-Mail
%>
				<span class="tag bottom tool blue" onclick="Task.applyTask(-2);">提出接案申請</span>
<%
		}else if(Profile.getProfile(user.id) == null){	//未建立譯者資料
%>
				<span class="tag bottom tool blue" onclick="Task.applyTask(-3);">提出接案申請</span>
<%
		}else if(Task.checkAppliedTask(task.id, user.id)){
%>
				<span class="tag bottom tool blue" onclick="Task.unapplyTask(<%= tid %>);">撤回接案申請</span>
<%
		}else{
%>
				<span class="tag bottom tool blue" onclick="Task.applyTask(<%= tid %>);">提出接案申請</span>
<%
		}
	}
%>
				<span class="tag bottom tool blue" onclick="Task.popup('/task/task-question.jsp', <%= tid %>);">
					問與答 (<%= task.question %>)
				</span>
			</div>
		</div>
<%@ include file="/include/foot.jsp" %>
	</div>
</body>
</html>